package handler

import (
	"apitestAfterGo/utils"
	"github.com/go-playground/validator/v10"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/context"
	"net/http"
)

func ValidateHandler(ctx *context.Context, err error) {
	if errs, ok := err.(validator.ValidationErrors); ok {
		validationErrors := utils.WrapValidationErrors(errs)
		ctx.Application().Logger().Infof("请求路径:%s,错误原因:请求参数错误或者不完整！", ctx.Path())
		ctx.JSON(iris.Map{
			"code": -99999,
			"msg":  "请求参数不完整",
			"data": validationErrors,
		})
		ctx.StopWithStatus(http.StatusOK)
	}
}
